package org.dearsor.elective.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.Transient;

@Entity
public class Student extends Person {
	
	
	private List<Course> courses;

	public void setCourses(List<Course> course) {
		this.courses = course;
	}

	@ManyToMany(cascade = CascadeType.ALL)
	public List<Course> getCourses() {
		if (courses == null) {
			courses = new ArrayList<Course>();
		}
		return courses;
	}
	
	@Transient
	public int getTotalScore() {
		int result = 0;
		for (Course course : getCourses()) {
			result += course.getScore();
		}
		return result;
	}

}
